package com.gf.gf_data.dto;

import com.gf.gf_data.sys.exception.ExceptionEnum;

/**
 * 返回错误信息提示
 *
 * Created by Eternal_L on 2018/1/9.
 */
public enum ResultMessage {

    /**无数据*/
    NO_DATA(8000, "the requested data does not exist"),

    /**登录失败*/
    LOGIN_FAILURE(9000, "login authentication failed"),
    /**无效用户*/
    INVALID_TOKEN(9001, "invalid token"),
    /**用户名或密码错误*/
    WRONG_ACCOUNT_NAME_OR_PASSWORD(9002, "wrong user name or password"),
    /**账户不可用*/
    ACCOUNT_IS_NOT_AVAILABLE(9003, "username is not available"),
    /**token数据异常*/
    TOKEN_DATA_ID_ABNORMAL(9004, "data is abnormal");




    private int state;    // 状态码

    private String msg;   // 异常描述信息

    ResultMessage(int state, String msg) {
        this.state = state;
        this.msg = msg;
    }

    public int getState() {
        return state;
    }

    public String getMsg() {
        return msg;
    }

    public static ExceptionEnum stateOf(int index) {
        for (ExceptionEnum resultEnum : ExceptionEnum.values()) {
            if (resultEnum.getState() == index) {
                return resultEnum;
            }
        }
        return null;
    }

    public static String stateOfValue(int index) {
        for (ExceptionEnum resultEnum : ExceptionEnum.values()) {
            if (resultEnum.getState() == index) {
                return resultEnum.getMsg();
            }
        }
        return null;
    }

}
